# ============================================================
# * Copyright © hk. 2022-2025. All rights reserved.
# * File name: CMakeLists.txt
# * Author   : 苏木
# * Date     : 2025-05-22
# * Version  : 
# * Description: cmake version 3.16.3
# ============================================================
## https://cmake.com.cn/cmake/help/latest/guide/tutorial/index.html
## https://cmake.org/cmake/help/latest/

# 指定 CMake 的最低版本要求
# --------------------------------------------------
cmake_minimum_required(VERSION 3.10)


# 设置项目名称和使用的编程语言
# --------------------------------------------------
project(SPROJECT C)


# 指定可执行程序和源文件
# --------------------------------------------------
add_executable(app_demo.out main.c)


# 复制文件
# --------------------------------------------------
# configure_file(source destination [COPYONLY | @ONLY] [ESCAPE_QUOTES])
# source      输入文件的路径。相对路径相对于 CMAKE_CURRENT_SOURCE_DIR 的值处理。输入路径必须是文件，而不是目录。
# destination 输出文件或目录的路径。相对路径相对于 CMAKE_CURRENT_BINARY_DIR 的值处理。如果路径指定一个现有目录，
# 			  则输出文件将放置在该目录中，文件名与输入文件相同。如果路径包含不存在的目录，则会创建这些目录。
# configure_file()最好只用于不需要经常更改的文件。
message(STATUS "==> ${CMAKE_VERSION} 复制文件并替换变量")
set(FOO "String with spaces")
configure_file(various.txt.in various.txt)
# 当要复制的文件中存在 ${someVar} 和 @someVar@ 的形式的变量时，若是 someVar 在cmkae中有定义，那么生成的文件中这两种
# 形式的变量会替换为对应的值，若不存在someVar，怎会替换一个空字符串
message("")

# 输出结果

# ==> various.txt.in：
# CMake version: ${CMAKE_VERSION}
# Substitution works inside quotes too: "${FOO}"
# No substitution without the $ and {}: FOO
# Empty ${} specifier gets removed
# Escaping has no effect: \${FOO}
# @-syntax also supported: @FOO@

# ==> various.txt：
# CMake version: 3.16.3
# Substitution works inside quotes too: "String with spaces"
# No substitution without the $ and {}: FOO
# Empty  specifier gets removed
# Escaping has no effect: \String with spaces
# @-syntax also supported: String with spaces

# ESCAPE_QUOTES关键字看作为替换的引号前面加上反斜杠。
message(STATUS "==> ${CMAKE_VERSION} 复制文件并替换变量，转义反斜杠")
set(BAR "Some \"quoted\" value")
configure_file(quoting.txt.in quoting.txt) # 这里的结果中，不会含有 "Some \"quoted\" value" 中的两个反斜杠
configure_file(quoting.txt.in quoting_escaped.txt ESCAPE_QUOTES)
message("")

# 输出结果

# ==> quoting.txt.in
# A: @BAR@
# B: "@BAR@"

# ==> quoting.txt
# A: Some "quoted" value
# B: "Some "quoted" value"

# ==> quoting_escaped.txt
# A: Some \"quoted\" value
# B: "Some \"quoted\" value"